#include "AnimPlayer/Actions/FadeAction.h"
#include "CurveWrappers/FloatCurveWrapper.h"

void FFadeAction::OnInit()
{
	FActionBase::OnInit();
	if (Layer.IsValid() && CurveWrapper.IsValid())
	{
		const float Value = CurveWrapper->GetValueByTime(0);
		Layer->DoFade(AnimTarget,ElementId,Value);
	}
}

void FFadeAction::OnBegin()
{
	FActionBase::OnBegin();
	if (Layer.IsValid() && CurveWrapper.IsValid())
	{
		const float Value = CurveWrapper->GetValueByTime(0);
		Layer->DoFade(AnimTarget,ElementId,Value);
	}
}

void FFadeAction::OnTick(float DeltaTime)
{
	FActionBase::OnTick(DeltaTime);
	if (Layer.IsValid() && CurveWrapper.IsValid())
	{
		const float Value = CurveWrapper->GetValueByTime(Timer);
		Layer->DoFade(AnimTarget,ElementId,Value);
	}
}

void FFadeAction::OnEnd()
{
	FActionBase::OnEnd();
	if (Layer.IsValid() && CurveWrapper.IsValid())
	{
		const float Value = CurveWrapper->GetValueByTime(Duration);
		Layer->DoFade(AnimTarget,ElementId,Value);
	}
}
